package com.ts.utils;

import java.io.StringReader;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import javax.xml.transform.stream.StreamSource;

public class XmlToBean {

	@SuppressWarnings("unchecked")
	public static <T> T standerdBean(String tXMLStr, Class<T> type) {
		T sqx = null;
		try {
			JAXBContext cxt = JAXBContext.newInstance(type);
			Unmarshaller unmarshaller = cxt.createUnmarshaller();
			StreamSource streamSource = new StreamSource(new StringReader(tXMLStr.toString()));
			sqx = (T) unmarshaller.unmarshal(streamSource);
		} catch (JAXBException e) {
			e.printStackTrace();
		}
		return sqx;
	}
}
